﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AnesSystem.Models;

namespace AnesSystem.ViewModels
{
    public class PacuAutoShowSignsCtrlViewModel : BaseViewModel<PacuAutoShowSignsCtrlViewModel>
    {
        #region Variables
        private ObservableCollection<ConfigVitalSignsModel> _autoShowSignsList;
        private ConfigVitalSignsModel _selectAutoShowSign;
        private ObservableCollection<ConfigVitalSignsModel> _tableShowSignList = new ObservableCollection<ConfigVitalSignsModel>();
        private ObservableCollection<ConfigVitalSignsModel> _lineShowSignList = new ObservableCollection<ConfigVitalSignsModel>();
        private Dictionary<string, int> _tableViatal2Index = new Dictionary<string, int>();

        #endregion


        #region Constructor
        public PacuAutoShowSignsCtrlViewModel()
        {
            _autoShowSignsList = new ObservableCollection<ConfigVitalSignsModel>();
        }



        #endregion


        #region Properties
        public ObservableCollection<ConfigVitalSignsModel> AutoShowSignsList
        {
            get
            {
                return _autoShowSignsList;
            }

            set
            {
                _autoShowSignsList = value;
            }
        }

        public ConfigVitalSignsModel SelectAutoShowSign
        {
            get
            {
                return _selectAutoShowSign;
            }

            set
            {
                _selectAutoShowSign = value;
            }
        }

        public ObservableCollection<ConfigVitalSignsModel> TableShowSignList
        {
            get
            {
                return _tableShowSignList;
            }

            set
            {
                _tableShowSignList = value;
            }
        }

        public ObservableCollection<ConfigVitalSignsModel> LineShowSignList
        {
            get
            {
                return _lineShowSignList;
            }

            set
            {
                _lineShowSignList = value;
            }
        }

        public Dictionary<string, int> TableViatal2Index
        {
            get
            {
                return _tableViatal2Index;
            }

            set
            {
                _tableViatal2Index = value;
            }
        }




        #endregion


        #region 依赖属性


        #endregion


        #region Event


        #endregion


        #region PrivateMethods
        private void ChangeShowWay()
        {
            for (int i = 1; i <= DataManager.Instance.CurrentPatientLink.Status.PacuPage; i++)
            {
                (DataManager.Instance.PacuRecordCtrl.DataContext as PacuRecordCtrlViewModel).PacuRecordCtrlViewModels[i].PacuRealTimeItemCtrlViewModel.ChangeVitalTotal();
            }
            RefershTableVitalIndex();
        }

        #endregion


        #region Public/ProtectedMethods
        public void ChangeAutoShowSelectSign(ConfigVitalSignsModel configVitalSignsModel)
        {
            _selectAutoShowSign = configVitalSignsModel;
        }
        /// <summary>
        /// 表格显示改变
        /// </summary>
        /// <returns></returns>
        public Dictionary<string, int> RefershTableVitalIndex()
        {
            _tableViatal2Index.Clear();
            for (int i = 0; i < TableShowSignList.Count; i++)
            {
                _tableViatal2Index.Add(TableShowSignList[i].code, i);
            }
            return _tableViatal2Index;
        }

        ///
        public void ChangShowWayFromLine2Table(ConfigVitalSignsModel cvs)
        {
            int index = -1;
            for (int i = 0; i < LineShowSignList.Count; i++)
            {
                if (LineShowSignList[i].code.Equals(cvs.code))
                {
                    index = i;
                    break;
                }
            }
            if (index != -1)
            {
                LineShowSignList.RemoveAt(index);
                TableShowSignList.Add(cvs);
                ChangeShowWay();
            }

        }
        public void ChangShowWayFromTable2Line(ConfigVitalSignsModel cvs)
        {
            int index = -1;
            for (int i = 0; i < TableShowSignList.Count; i++)
            {
                if (TableShowSignList[i].code.Equals(cvs.code))
                {
                    index = i;
                    break;
                }
            }
            if (index != -1)
            {
                TableShowSignList.RemoveAt(index);
                LineShowSignList.Add(cvs);
                ChangeShowWay();
            }

        }

        public void RemoveAutoShowListByCode(string code)
        {
            if (string.IsNullOrEmpty(code))
            {
                return;
            }
            int index = -1;
            for (int i = 0; i < AutoShowSignsList.Count; i++)
            {
                if (code.Equals(AutoShowSignsList[i].code))
                {
                    index = i;
                    break;
                }
            }
            if (index != -1)
            {
                AutoShowSignsList.RemoveAt(index);
            }
        }

        public void RemoveLineShowListByCode(string code)
        {
            if (string.IsNullOrEmpty(code))
            {
                return;
            }
            int index = -1;
            for (int i = 0; i < LineShowSignList.Count; i++)
            {
                if (code.Equals(LineShowSignList[i].code))
                {
                    index = i;
                    break;
                }
            }
            if (index != -1)
            {
                LineShowSignList.RemoveAt(index);
            }
        }

        public void RemoveTableShowListByCode(string code)
        {
            if (string.IsNullOrEmpty(code))
            {
                return;
            }
            int index = -1;
            for (int i = 0; i < TableShowSignList.Count; i++)
            {
                if (code.Equals(TableShowSignList[i].code))
                {
                    index = i;
                    break;
                }
            }
            if (index != -1)
            {
                TableShowSignList.RemoveAt(index);
            }
        }

        #endregion


        #region EventHandlers


        #endregion
    }
}
